package com.my_musc_service.controller.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.my_musc_service.common.R;
import com.my_musc_service.entity.*;
import com.my_musc_service.service.QueryService;
import com.my_musc_service.service.SharedSongListService;
import com.my_musc_service.service.SharedSongService;
import com.my_musc_service.service.SongService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zhudunfeng
 * @date 2021/6/16 17:33
 */
@Slf4j
@RestController
@RequestMapping(value = "query")
public class QueryController {

    @Resource
    private QueryService queryService;

    @Resource
    private SharedSongService sharedSongService;

    @Resource
    private SharedSongListService sharedSongListService;



    @GetMapping("all")
    public R querySongOrList(QueryAllVO queryAllVO) {
        Map<String, Object> map = queryService.querySongOrList(queryAllVO);
        return R.ok().data(map);
    }

    @GetMapping("allLike")
    public R querySongOrListLike(QueryAllVO queryAllVO) {
        Map<String, Object> map = queryService.querySongOrListLike(queryAllVO);
        return R.ok().data(map);
    }

    @GetMapping("lyric")
    public R queryLyricByUrl(@RequestParam("url") String url) {
        String lyric = queryService.queryLyricByUrl(url);
        return R.ok().data("lyric", lyric);
    }

    @GetMapping("shared")
    public R queryAllShared(
            @RequestParam("page") Long page,
            @RequestParam("limit") Long limit
    ){
        Page<SharedSongVO> sharedSongPageParam = new Page<>(page,limit);
        Page<SharedSongListVO> sharedSongListPageParam = new Page<>(page,limit);

        Map<String, Object> sharedSongVOData = sharedSongService.selectSharedSongVOData(sharedSongPageParam);
//        sharedSongListService.selectPage(sharedSongListPageParam,null);
        Map<String, Object> sharedSongListData = sharedSongListService.getSharedSongListData(sharedSongListPageParam);

        Map<String, Object> returnMap = new HashMap<>();
//        returnMap.put("sharedSongTotal", sharedSongPageParam.getTotal());
//        returnMap.put("sharedSongList", sharedSongPageParam.getRecords());

//        returnMap.put("sharedSongListTotal", sharedSongListPageParam.getTotal());
//        returnMap.put("sharedSongListList", sharedSongListPageParam.getRecords());
        returnMap.putAll(sharedSongVOData);
        returnMap.putAll(sharedSongListData);

        return R.ok().data(returnMap);
    }

}
